class DateFormatter {
  format(date: any, format: string) {
    try {
      let realDate = new Date(date);
      let ret = format;
      ret = ret.replaceAll("yyyy", realDate.getFullYear().toString());
      ret = ret.replaceAll("yy", realDate.getFullYear.toString().substring(2));
      ret = ret.replaceAll(
        "mm",
        (realDate.getMonth() + 1 < 10 ? "0" : "") +
          (realDate.getMonth() + 1).toString()
      );
      ret = ret.replaceAll(
        "dd",
        (realDate.getDate() < 10 ? "0" : "") + realDate.getDate().toString()
      );
      ret = ret.replaceAll(
        "HH",
        (realDate.getHours() < 10 ? "0" : "") + realDate.getHours()
      );
      ret = ret.replaceAll(
        "mm",
        (realDate.getMinutes() < 10 ? "0" : "") + realDate.getMinutes()
      );
      ret = ret.replaceAll(
        "ss",
        (realDate.getSeconds() < 10 ? "0" : "") + realDate.getSeconds()
      );
      return ret;
    } catch {
      return "";
    }
  }
}

export default new DateFormatter();
